require 'middleclass'
require 'SpriteHelper'

StatusBar = class('StatusBar')

function StatusBar:initialize(x , y, imageSheet)
    self.starCounter = 0
    self.livesCounter = 3
    self.starImage = display.newImageRect(imageSheet,SpriteHelper.sheets.star ,20,20)
    self.starImage.x = x
    self.starImage.y = y + 10
    self.starDisplay = display.newText( self.starCounter, x + 20, y, "Helvetica", 20)
    self.livesImage = display.newImageRect(imageSheet,SpriteHelper.sheets.tree1 ,20,20)
    self.livesImage.x = x + 100
    self.livesImage.y = y + 10
    self.livesDisplay = display.newText( self.livesCounter, x + 120, y, "Helvetica", 20)
    
    Runtime:addEventListener("star", self)
    Runtime:addEventListener("live", self)
    Runtime:addEventListener("clean", self)
end

function StatusBar:star()
    self.starCounter =  self.starCounter + 1
    self.starDisplay.text = self.starCounter
end

function StatusBar:live()
    self.livesCounter =  self.livesCounter -1
    self.livesDisplay.text = self.livesCounter
end

function StatusBar:clean()
    Runtime:removeEventListener("star", self)
    Runtime:removeEventListener("live", self)
    Runtime:removeEventListener("clean", self)
    self.starImage:removeSelf()
    self.starDisplay:removeSelf()
    self.livesDisplay:removeSelf()
    self.livesImage:removeSelf()
end
